package com.fyt.recover.order;

public class MergeOrder {
     static int [] assist;
    public static void sort(int[]arr,int low,int high){
        if(low>=high){
            return;
        }
        int mid=low+(high-low)/2;
        sort(arr,low,mid);
        sort(arr,mid+1,high);


        merge(arr,low,high,mid);

    }


    public static void merge(int[]arr, int low,int high,int mid){

        int x=low;
        int y=mid+1;
        int z=low;

        while (x<=mid&&y<=high){
            if(arr[x]<=arr[y]){
                assist[z++]=arr[x++];

            }
            else assist[z++]=arr[y++];


        }

        while (x<=mid){
            assist[z++]=arr[x++];
        }

        while (y<=high){
          assist[z++]=arr[y++];
        }

        for (int i = low; i <=high; i++) {
            arr[i]=assist[i];
        }

    }

    public static void start(int[] arr) {

        assist=new int [arr.length];
        sort(arr,0,arr.length-1);
        /*for (int i = 0; i <arr.length ; i++) {
            arr[i]=assist[i];

        }*/


        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

    }


}
